﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using CVSS.Client.CIQS.Entity.StatAlarm;
using SysCommon.Business.CVSS.WS.BaseData;
using SysCommon.Entity.Business.Stat;
using SysCommon.Entity.CVSS.WS.BaseData;
using SysCommon.Tools;
using SysCommon.Entity.CVSS.WS.Stat;

namespace CVSS.Client.CIQS.UI
{
    public class AreaAlarmStatFormMDT
    {
        AreaAlarmStatForm frm = new AreaAlarmStatForm();
        string m_CurrentOrgName="";

        #region 界面初始化ShowForm()
        /// <summary>
        /// 界面初始化
        /// </summary>
        /// <returns></returns>
        public bool ShowForm()
        {
            try
            {
                frm.Load += new EventHandler(frm_Load);

                frm.ShowDialog();
                return true;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberAlarmStatFormMDT的Show函数出错", ex);
            }
            return false;
        }
        #endregion

        void frm_Load(object sender, EventArgs e)
        {
            SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载窗体，请稍候...");
            System.Windows.Forms.Application.DoEvents();
            //
            //打印
            frm.btn_Print.Click += new EventHandler(btn_Print_Click);
            //
            //导出Excel表
            frm.btn_ExportToExcel.Click += new EventHandler(btn_ExportToExcel_Click);
            //
            //开始统计
            frm.btn_Start.Click += new EventHandler(btn_Start_Click);
            //
            frm.FormClosing += new FormClosingEventHandler(frm_FormClosing);
            //frm.Load+=new EventHandler(frm_Load);
         
            InitCarMember(frm.cmb_CarMember);
            InitCarType(frm.cmb_CarType);
            InitDataView();
            //InitDataView2();
            InitDataGridView();
            SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
        }

        #region frm_FormClosing
        void frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                CVSS.Client.CIQS.Data.ExcelData.QuitExcelHandler();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberAlarmStatFormMDT的frm_FormClosing(object sender, FormClosingEventArgs e)函数出错", ex);
            }
        }
        #endregion

        #region 显示数据
        private void ShowDataView(object[] etys)
        {
            try
            {
                string[] cnColumns = new string[] { "辖区名称", "车辆类型", "报警数量" };
                string[] enColumns = new string[] { "AREANAME", "CARTYPENAME", "ALARMNUM"};
                ShowEntityForDataGridView.SetDefaultDataGrigStyle(frm.dvp_DataView.dg_DataView);

                ShowEntityForDataGridView.EntityToView(cnColumns, enColumns, etys, frm.dvp_DataView.dg_DataView);

                frm.dvp_DataView.dg_DataView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用ShowDataView出错", ex);
            }
        }
        #endregion

        #region 获取统计信息
        SysCommon.Entity.CVSS.WS.Stat.View_Statisticareaa_Ety[] GetStatInfo(
            SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety query)
        {
            try
            {
                SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();
                SysCommon.Entity.CVSS.WS.Stat.View_Statisticareaa_Ety[] etys = ws.AreaAlarmSta(query);
                
                return etys;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用GetStatInfo(SysCommon.Entity.CVSS.WS.Stat.QueryCondition_Ety query)出错", ex);
            }
            return null;
        }
        #endregion

        #region 获取统计信息(webservice压缩处理)
        /// <summary>
        ///  获取统计信息(webservice压缩处理)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] GetStatInfo2(
            SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety query)
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = null;
                
                SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();
                byte[] zipBuffer = ws.AreaAlarmSta2(query);
                etys = (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[])CompressionHelper.DeCompressEntity(zipBuffer);

                return etys;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用GetStatInfo(SysCommon.Entity.CVSS.WS.Stat.QueryCondition_Ety query)出错", ex);
            }
            return null;
        } 
        #endregion

        #region 获取统计信息压缩分页
        /// <summary>
        /// 获取统计信息压缩分页
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] GetStatInfoWithCompressForPage(
            SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety query)
        {
            int pageIndex = 1;
            int pageSize = 30;

            SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = null;

            SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();
            byte[] zipBuffer = ws.AreaAlarmStaWithCompressForPage(query, pageIndex, pageSize);
            object obj = null;
            if (zipBuffer != null)
            {
                obj = SysCommon.Tools.CompressionHelper.DeCompressEntity(zipBuffer);
                InitDataGridView();
            }
            SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety> result = obj
                as SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety>;

            if (result == null)
            {
                result = new SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety>();
                result.Objects = null;
                result.PageCount = 0;
                result.PageIndex = 0;
                result.PageSize = 0;
            }
            string[] cnColumns = new string[] { "辖区名称", "车辆类型", "报警数量" };
            string[] enColumns = new string[] { "AREANAME", "CARTYPENAME", "ALARMNUM" };
            if (result != null)
            {
                frm.dvp_DataView.Init(result.PageIndex, result.PageCount, result.PageSize, result.Objects, cnColumns, enColumns);

            }

            else
            {
                //SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys =
                //    new SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[0];
                frm.dvp_DataView.Init(0, 0, 0, etys, enColumns, cnColumns);
            }
            frm.dvp_DataView.OnDataChangedHandlerEvent += new SysCommon.UI.DataGridViewForPageCtrl.OnDataChangedHandler(dvp_DataView_OnDataChangedHandlerEvent);
            return etys;
        }
        #endregion

        #region InitDataGridView
        /// <summary>
        /// 初始化DataGridView
        /// </summary>
        void InitDataGridView()
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys =
                    new SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[0];
                if (etys == null) return;
                string[] cn_col = new string[] { "辖区名称", "车辆类型", "报警数量" };
                string[] en_col = new string[] { "AREANAME", "CARTYPENAME", "ALARMNUM" };


                SysCommon.Tools.ShowEntityForDataGridView.SetDefaultDataGrigStyle(frm.dvp_DataView.dg_DataView);
                SysCommon.Tools.ShowEntityForDataGridView.EntityToView(cn_col, en_col, etys, frm.dvp_DataView.dg_DataView);
                frm.dvp_DataView.dg_DataView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CVSS.Client.CIQS.UI.InitDataGridView出错", ex);
            }
        }
        #endregion
       

        #region dvp_DataView_OnDataChangedHandlerEvent
        /// <summary>
        /// 数据改变时的处理函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">当前页面数据参数</param>
        /// <returns>新数据</returns>
        object dvp_DataView_OnDataChangedHandlerEvent(object sender, SysCommon.UI.DataGridViewForPageCtrl.OnDataChangedHandlerEventArgs e)
        {
            int pageIndex = e.PageIndex;
            int countPerPage = e.PageSize;
            int pageSize = e.PageSize;
            SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载数据，请稍候...");
            System.Windows.Forms.Application.DoEvents();
            //SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = null;
            SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety query = new SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety();
            SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();

            query.BEGINTIME = frm.dtp_FromDate.Value;
            query.ENDTIME = frm.dtp_ToDate.Value;
            query.AREANAME = frm.cmb_CarMember.Text.Trim().Replace("全部", "");
            query.CARTYPE = frm.cmb_CarType.Text.Trim();
            //filter.CARMEMBERNAME.Replace("全部", "").Replace("广东省","");
            if (query.CARTYPE == "全部") query.CARTYPE = "";

            byte[] zipBuffer = ws.AreaAlarmStaWithCompressForPage(query, pageIndex, pageSize);
           int i= frm.dvp_DataView.dg_DataView.ColumnCount;
            object obj = null;
            if (zipBuffer != null)
            {
                obj = SysCommon.Tools.CompressionHelper.DeCompressEntity(zipBuffer);
               
                //InitDataGridView();
            }
            SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety> result = obj
                as SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety>;

            if (result != null)
            {
                SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
                    return result.Objects;
            }
                return null;
        }
        #endregion

        #region 统计方法调用Stat()
        /// <summary>
        /// 统计方法调用
        /// </summary>
        void Stat()
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的btn_Start_Click函数");
                SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载数据，请稍候...");
                System.Windows.Forms.Application.DoEvents();

                frm.btn_Start.Enabled = false;
                SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety filter = new SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety();

                filter.BEGINTIME = frm.dtp_FromDate.Value;
                filter.ENDTIME = frm.dtp_ToDate.Value;
                filter.AREANAME = frm.cmb_CarMember.Text.Trim().Replace("全部", "");
                filter.CARTYPE = frm.cmb_CarType.Text.Trim();
                //filter.CARMEMBERNAME.Replace("全部", "").Replace("广东省","");
                if (filter.CARTYPE == "全部") filter.CARTYPE = "";

                //SysCommon.Entity.CVSS.WS.Stat.View_Statisticareaa_Ety[] etys = GetStatInfo(filter);//备份
                //SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = GetStatInfo2(filter);//压缩备份
                SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = GetStatInfoWithCompressForPage(filter);

                SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
                #region 备份
                //if (etys == null)
                //{
                //    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有找到符合条件的结果", false);
                //    frm.btn_Start.Enabled = true;
                //    return;
                //}

                //ShowDataView(etys);

                //if (etys.Length == 0)
                //{
                //    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有找到符合条件的结果", false);
                //    frm.btn_Start.Enabled = true;
                //    return;
                //}
                #endregion

                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的btn_Start_Click函数结束");
                frm.btn_Start.Enabled = true;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的btn_Return_Click函数出错", ex);
            }
        }
        #endregion

        #region 开始统计
        /// <summary>
        /// 开始统计数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btn_Start_Click(object sender, EventArgs e)
        {
            try
            {
                SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载数据，请稍候...");
                System.Windows.Forms.Application.DoEvents();
                Stat();
                SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] m_Etys = (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[])frm.dvp_DataView.dg_DataView.DataSource;

                SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
                if (m_Etys == null || m_Etys.Length == 0)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有找到符合条件的结果", false);
                }
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用btn_Query_Click(object sender, EventArgs e)出错", ex);
            }
        }
        #endregion

        #region 导出到Excel
        /// <summary>
        /// 导出到Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btn_ExportToExcel_Click(object sender, EventArgs e)
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的btn_ExportToExcel_Click函数");
                frm.btn_ExportToExcel.Enabled = false;
                ExportExcel();
                frm.btn_ExportToExcel.Enabled = true;
                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的btn_ExportToExcel_Click函数结束");
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的btn_ExportToExcel_Click函数出错", ex);
                frm.btn_ExportToExcel.Enabled = true;
            }
        }
        #endregion

        #region 打印
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btn_Print_Click(object sender, EventArgs e)
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的btn_Print_Click函数");
                Print();
                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的btn_Print_Click函数结束");
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的btn_Print_Click函数出错", ex);
            }
        }
        #endregion

        #region 初始化车辆类型
        /// <summary>
        /// 初始化车辆类型
        /// </summary>
        /// <param name="m_ComboBox"></param>
        void InitCarType(System.Windows.Forms.ComboBox m_ComboBox)
        {
            GetSystemSettings("VehicleType", m_ComboBox);
        }
        #endregion

        #region 初始化辖区列表
        /// <summary>
        /// 初始化辖区列表
        /// </summary>
        /// <param name="m_ComboBox"></param>
        void InitCarMember(System.Windows.Forms.ComboBox m_ComboBox)
        {
            /*
            m_ComboBox.Items.Clear();
            WS_BaseData_BizCtrlImpl m_ws = new WS_BaseData_BizCtrlImpl();
            AreaCode_Ety[] m_Etys = m_ws.GetAllAreaInfo();
            //CarMember_Ety[] m_Etys = m_ws.GetAllCarMemberInfo();
            m_ComboBox.Items.Add("全部");
            foreach (AreaCode_Ety ety in m_Etys)
            {
                if (ety.NAME == null) continue;
                m_ComboBox.Items.Add(ety.NAME);
            }
            m_ComboBox.Text = "全部";
            */
            try
            {
                SysCommon.Entity.CVSS.WS.BaseData.View_Organization_Ety org = CIQS.CIQSGlobal.GetCurrentOrganization();
                string strAreaCode = org.AREACODE;
                m_CurrentOrgName = org.AREANAME;

                if (strAreaCode.EndsWith("0000"))
                {
                    strAreaCode = "44";
                }
                else
                {
                    strAreaCode = strAreaCode.Substring(0, 4);
                }
                SysCommon.Business.CVSS.WS.BaseData.WS_BaseData_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.BaseData.WS_BaseData_BizCtrlImpl();

                SysCommon.Entity.CVSS.WS.BaseData.AreaCode_Ety[] areaCode = ws.GetAllAreaInfo();

                m_ComboBox.Items.Clear();
                m_ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                m_ComboBox.Items.Add("全部");
                foreach (SysCommon.Entity.CVSS.WS.BaseData.AreaCode_Ety code in areaCode)
                {
                    if (code.CODE.Contains(strAreaCode))
                    {
                        m_ComboBox.Items.Add(code.NAME);
                    }
                }
                frm.cmb_CarMember.Text = "全部";
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("初始化辖区列表出错！", ex);
            }
        }
        #endregion
        #region 初始化辖区列表(webservice压缩处理)
        /// <summary>
        /// 初始化辖区列表(webservice压缩处理)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="m_ComboBox"></param>
        void InitCarMember2(System.Windows.Forms.ComboBox m_ComboBox)
        {
            try
            {
                SysCommon.Entity.Business.AreaCode_Ety[] areaCode = null;
                SysCommon.Entity.CVSS.WS.BaseData.View_Organization_Ety org = CIQS.CIQSGlobal.GetCurrentOrganization();
                string strAreaCode = org.AREACODE;
                m_CurrentOrgName = org.AREANAME;

                if (strAreaCode.EndsWith("0000"))
                {
                    strAreaCode = "44";
                }
                else
                {
                    strAreaCode = strAreaCode.Substring(0, 4);
                }
                SysCommon.Business.CVSS.WS.BaseData.WS_BaseData_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.BaseData.WS_BaseData_BizCtrlImpl();

               byte[] zipBuffer = ws.GetAllAreaInfo2();
               areaCode = (SysCommon.Entity.Business.AreaCode_Ety[])CompressionHelper.DeCompressEntity(zipBuffer);

                m_ComboBox.Items.Clear();
                m_ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                m_ComboBox.Items.Add("全部");
                foreach (SysCommon.Entity.Business.AreaCode_Ety code in areaCode)
                {
                    if (code.CODE.Contains(strAreaCode))
                    {
                        m_ComboBox.Items.Add(code.NAME);
                    }
                }
                frm.cmb_CarMember.Text = "全部";
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("初始化辖区列表出错！", ex);
            }
        }
        #endregion

        #region 获取系统配置信息
        /// <summary>
        /// 获取系统配置信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="m_ComboBox"></param>
        void GetSystemSettings(string name, System.Windows.Forms.ComboBox m_ComboBox)
        {
            m_ComboBox.Items.Clear();
            WS_BaseData_BizCtrlImpl m_ws = new WS_BaseData_BizCtrlImpl();
            SysSetting_Ety[] etys = m_ws.SearchSysSettingInfo1(name);

            foreach (SysSetting_Ety ety in etys)
            {
                m_ComboBox.Items.Add(ety.DISPLAYVALUE);
            }
            if (m_ComboBox.Items.Count > 0)
            {
                m_ComboBox.Text = "全部";
            }
        }
        #endregion

        #region 初始化dataGridView
        /// <summary>
        /// 初始化dataGridView
        /// </summary>
        void InitDataView()
        {
            try
            {
                SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety filter = new SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety();
                SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();

                //filter.CARMEMBERNAME = "";
                filter.CARTYPE = "";
                filter.BEGINTIME = System.DateTime.Now.AddDays(-1);
                filter.ENDTIME = System.DateTime.Now;

                SysCommon.Entity.CVSS.WS.Stat.View_Statisticareaa_Ety[] etys = ws.AreaAlarmSta(filter);
                if (etys == null)
                {
                    etys = new SysCommon.Entity.CVSS.WS.Stat.View_Statisticareaa_Ety[0];
                }
                //ShowDataView(etys);
                InitDataGridView();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用InitDataView()出错！", ex);
            }
        }
        #endregion
        #region 初始化dataGridView(webservice压缩处理)
        /// <summary>
        /// 初始化dataGridView(webservice压缩处理)
        /// </summary>
        void InitDataView2()
        {
            try
            {
               SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = null;
                SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety filter = new SysCommon.Entity.CVSS.WS.Stat.AreaStaA_Ety();
                SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();

                //filter.CARMEMBERNAME = "";
                filter.CARTYPE = "";
                filter.BEGINTIME = System.DateTime.Now.AddDays(-1);
                filter.ENDTIME = System.DateTime.Now;

               byte[] zipBuffer = ws.AreaAlarmSta2(filter);
               etys = (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[])CompressionHelper.DeCompressEntity(zipBuffer);

                if (etys == null)
                {
                    etys = new SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[0];
                }
                //ShowDataView(etys);
                InitDataGridView();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用InitDataView()出错！", ex);
            }
        }
        #endregion


        #region 打印实现函数
        /// <summary>
        /// 实现打印函数
        /// </summary>
        void Print()
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[])frm.dvp_DataView.dg_DataView.DataSource;
                if (etys == null)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要打印的数据", false);
                    return;
                }
                if (etys.Length == 0)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要打印的数据", false);
                    return;
                }
                //统计信息            
                string carmembernames = "";
                //Dictionary<string, Result_Ety> results = new Dictionary<string, Result_Ety>();
                System.Collections.Hashtable results = new System.Collections.Hashtable();

                string tmpname = "";
                foreach (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety ety in etys)
                {
                    CVSS.Client.CIQS.Entity.Stat.Alarm.Result_Ety re_ety =
                        new CVSS.Client.CIQS.Entity.Stat.Alarm.Result_Ety();

                    tmpname = ety.AREANAME;
                    if (results.ContainsKey(tmpname))
                    {
                        re_ety = (CVSS.Client.CIQS.Entity.Stat.Alarm.Result_Ety)results[tmpname];
                        CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety pe = GetCarType(ety.CARTYPE, ety.ALARMNUM);
                        if (re_ety.CarType == null)
                        {
                            re_ety.CarType = pe;
                        }
                        else
                        {
                            re_ety.CarType.BusNumber += pe.BusNumber;
                            re_ety.CarType.DangerCarNumber += pe.DangerCarNumber;
                            re_ety.CarType.CarNumber += pe.CarNumber;
                            re_ety.CarType.TruckNumber += pe.TruckNumber;
                        }
                        results[tmpname] = re_ety;
                    }
                    else
                    {
                        carmembernames += tmpname + ",";
                        re_ety.StatTypeName = tmpname;
                        re_ety.CarType = new
                            CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety();
                        re_ety.CarType = GetCarType(ety.CARTYPE, ety.ALARMNUM);
                        results.Add(tmpname, re_ety);
                    }
                }
                carmembernames = carmembernames.Substring(0, carmembernames.Length - 1);
                string[] carmemberArray = carmembernames.Split(',');

                string path = Application.StartupPath + @"\Resource\ReportsTemplate\广东省车辆报警信息统计报表（辖区管理）.xls";
                DateTime[] datetime = new DateTime[2];
                datetime[0] = frm.dtp_FromDate.Value;
                datetime[1] = frm.dtp_ToDate.Value;

                CVSS.Client.CIQS.Data.ExcelData.PrintStatAlarmData(path, results, carmemberArray, datetime);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用Print()出错", ex);
            }
        }
        #endregion

        #region 实现导出Excel功能
        /// <summary>
        /// 实现导出Excel
        /// </summary>
        void ExportExcel()
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[] etys = (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety[])frm.dvp_DataView.dg_DataView.DataSource;
                if (etys == null)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要导出的数据", false);
                    return;
                }
                if (etys.Length == 0)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要导出的数据", false);
                    return;
                }
                //统计信息            
                string carmembernames = "";
                //Dictionary<string, Result_Ety> results = new Dictionary<string, Result_Ety>();
                System.Collections.Hashtable results = new System.Collections.Hashtable();

                string tmpname = "";
                foreach (SysCommon.Entity.Business.Stat.View.View_Statisticareaa_Ety ety in etys)
                {
                    CVSS.Client.CIQS.Entity.Stat.Alarm.Result_Ety re_ety =
                        new CVSS.Client.CIQS.Entity.Stat.Alarm.Result_Ety();

                    tmpname = ety.AREANAME;
                    if (results.ContainsKey(tmpname))
                    {
                        re_ety = (CVSS.Client.CIQS.Entity.Stat.Alarm.Result_Ety)results[tmpname];
                        CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety pe = GetCarType(ety.CARTYPE, ety.ALARMNUM);
                        if (re_ety.CarType == null)
                        {
                            re_ety.CarType = pe;
                        }
                        else
                        {
                            re_ety.CarType.BusNumber += pe.BusNumber;
                            re_ety.CarType.DangerCarNumber += pe.DangerCarNumber;
                            re_ety.CarType.CarNumber += pe.CarNumber;
                            re_ety.CarType.TruckNumber += pe.TruckNumber;
                        }
                        results[tmpname] = re_ety;
                    }
                    else
                    {
                        carmembernames += tmpname + ",";
                        re_ety.StatTypeName = tmpname;
                        re_ety.CarType = new
                            CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety();
                        re_ety.CarType = GetCarType(ety.CARTYPE, ety.ALARMNUM);
                        results.Add(tmpname, re_ety);
                    }
                }
                carmembernames = carmembernames.Substring(0, carmembernames.Length - 1);
                string[] carmemberArray = carmembernames.Split(',');

                string path = Application.StartupPath + @"\Resource\ReportsTemplate\广东省车辆报警信息统计报表（辖区管理）.xls";
                DateTime[] datetime = new DateTime[2];
                datetime[0] = frm.dtp_FromDate.Value;
                datetime[1] = frm.dtp_ToDate.Value;

                CVSS.Client.CIQS.Data.ExcelData.ExportStatAlarmData(path, results, carmemberArray, datetime);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用Print()出错", ex);
            }
        }
        #endregion

        #region 获取CarType_Ety
        /// <summary>
        /// 获取CarType_Ety车车辆类型
        /// </summary>
        /// <param name="carType"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety GetCarType(string carType, int number)
        {
            CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety ety =
                new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Alarm.CarType_Ety();
            switch (carType)
            {
                case "1":
                    ety.BusNumber = number;
                    ety.DangerCarNumber = 0;
                    ety.TruckNumber = 0;
                    ety.CarNumber = 0;
                    break;
                case "2":
                    ety.BusNumber = 0;
                    ety.DangerCarNumber = 0;
                    ety.TruckNumber = number;
                    ety.CarNumber = 0;
                    break;
                case "3":
                    ety.BusNumber = 0;
                    ety.DangerCarNumber = 0;
                    ety.TruckNumber = 0;
                    ety.CarNumber = number;
                    break;
                //case "4":
                //    ety.SeriousOverSpeed = number;
                //    break;
                case "5":
                    ety.BusNumber = 0;
                    ety.DangerCarNumber = number;
                    ety.TruckNumber = 0;
                    ety.CarNumber = 0;
                    break;
            }
            return ety;
        }
        #endregion
    }
}
